package com.jdz.noise.controller;

import com.jdz.noise.dao.FlyStatusDao;
import com.jdz.noise.entities.FlyStatus;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.List;

@Controller
public class IndexController {
    private final Logger logger= LoggerFactory.getLogger(IndexController.class);
    @Autowired
    private FlyStatusDao flyStatusDao;
    @GetMapping("/index")
    public String index(Model model) {

        return "index" +
                "";
    }

    @RequestMapping("/welcome")
    public String welcome() {

        return "welcome";
    }

    @RequestMapping("/member-list")
    public String member_list() {

        return "member-list";
    }
    @RequestMapping("/mamber-analysis")
    public String mamber_analysis() {

        return "mamber-analysis";
    }
    @RequestMapping("/member-list1")
    public String member_list1() {

        return "member-del";
    }    @RequestMapping("/member-del")
    public String member_del() {

        return "member-del";
    }

    @GetMapping("/member-listinfo")
    public String member_listinfo(Model model, @RequestParam(value = "indicatedAirspeed", required = false) String indicatedAirspeed){
//        FlyStatus fs=new FlyStatus(1, 1000,190.956,62.5978,385.125,412.0,615.0,23.25,"无描述");
        List<FlyStatus> res=null;
        if(indicatedAirspeed==null)
            res=flyStatusDao.getAllFlyStatusInfo();
        else
            try {
                res=flyStatusDao.getFlyRowByIndicatedAirspeed(Double.parseDouble(indicatedAirspeed));
            }catch (NumberFormatException e){
                logger.error("指空时速[{}]转型异常", indicatedAirspeed);
            }
        model.addAttribute("flyStatusInfo", res);
        return "member-listinfo";
    }
    @RequestMapping("/search")
    public String sphereTest(String v,Model model){
        double t = Double.parseDouble(v);
        System.out.println(t);
        List<FlyStatus> res=flyStatusDao.getFlyRowByIndicatedAirspeed(t);
        model.addAttribute("flyStatusInfo", res);
        return "member-listinfo";
    }


}
